<%--
  Created by IntelliJ IDEA.
  User: cos
  Date: 2022/3/14
  Time: 16:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .c1{
            color: red;
        }
    </style>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

</head>
<body>
<div>
    <h1 style="background-color: palegreen">这家电子文档</h1>
   <%-- <form action="/entry/add" method="post">--%>
    <form id="myForm">
    <table>
        <tr>
            <td>文档名称<span class="c1">(*)</span></td>
            <td>
                <input type="text" name="title">
            </td>
        </tr>
        <tr>
            <td>文档摘要</td>
            <td>
                <textarea name="summary"  cols="30" rows="10"></textarea>
            </td>
        </tr>
        <tr>
            <td>上传人</td>
            <td><input type="text" name="uploaduser"></td>
        </tr>
        <tr>
            <td>上传时间<span class="c1">(*)</span></td>
            <td><input type="date" name="createdate">(yyyy-MM-dd)</td>
        </tr>
        <tr>
            <td colspan="2">
                <select name="categoryId" id="categoryId">
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" id="btn2" value="提交">
                <button type="button" id="btn1">返回</button>
            </td>
        </tr>
    </table>
    </form>
</div>
<script>
    $(function () {
        $.ajax({
            type:"get",
            url:"/category/getAll",
            success:function (data) {
                for (let x in data) {
                    $("#categoryId").append("<option value='"+data[x].id+"'>"+data[x].name+"</option>")
                }
            }
        })
        $("#btn1").click(function () {
            //后退一页
            history.go(-1);
        })

        $("#btn2").click(function () {
            //获取数据
            var datas = $("#myForm").serialize();
            $.ajax({
                type: "post",
                url: "/entry/add",
                data:datas,
                success:function (data) {
                    if (data==1) {
                       alert("新增成功");
                       location.href="/index2.jsp";
                    }else{
                        alert("新增失败");
                    }
                }
            })
        })
    })
</script>
</body>
</html>
